<template>
  <div class="app-container">
    <el-table v-loading="listLoading" :data="list" border fit highlight-current-row style="width: 100%">
      <el-table-column align="center" label="编号" width="80">
        <template slot-scope="{row}">
          <router-link :to="'/edc/edit/'+row.DocEntry+'?code='+row.Code" class="link-type">
            <span>{{ row.DocEntry }}</span>
          </router-link>
        </template>
      </el-table-column>

      <el-table-column width="200px" align="center" label="数据编号">
        <template slot-scope="scope">
          <span>{{ scope.row.Code }}</span>
        </template>
      </el-table-column>

      <el-table-column width="200px" align="center" label="数据名称">
        <template slot-scope="scope">
          <span>{{ scope.row.Name }}</span>
        </template>
      </el-table-column>

      <el-table-column align="center" label="操作" width="120">
        <template slot-scope="scope">
          <router-link :to="'/edc/edit/'+scope.row.DocEntry+'?code='+scope.row.Code">
            <el-button type="primary" size="small" icon="el-icon-edit">
              Edit
            </el-button>
          </router-link>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
  </div>
</template>

<script>
import axios from 'axios'
import { fetchEDCs } from '@/api/res'
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination

export default {
  name: 'EdcList',
  components: { Pagination },
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'info',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      list: null,
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 20
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getTestList(){
      this.list = [{"row_number":"1","DocEntry":"7","Code":"shsc","Name":"熟化生产数据"},{"row_number":"2","DocEntry":"6","Code":"fqzl","Name":"分切质量数据"},{"row_number":"3","DocEntry":"5","Code":"fqsc","Name":"分切生产数据"},{"row_number":"4","DocEntry":"4","Code":"tbzl","Name":"涂布质量数据"},{"row_number":"5","DocEntry":"3","Code":"tbsc","Name":"涂布生产数据"},{"row_number":"6","DocEntry":"2","Code":"hjzl","Name":"混胶质量数据"},{"row_number":"7","DocEntry":"1","Code":"hjsc","Name":"混胶生产数据"}]

      //this.list = _list.sort((a,b)=>a.DocEntry - b.DocEntry)
      this.total = this.list.length
      this.listLoading = false
    },
    getList() {
      this.listLoading = true
      fetchEDCs(this.listQuery).then(res=>{
        const {flist, curPageList} = res
        console.log('success to get fetchEDCs',res)
        this.list = curPageList
        this.total = flist.length
        this.listLoading = false
      }).catch(err=>{
        this.listLoading = false
        console.log('failed to get fetchEDCs',err)
      })
    }
  }
}
</script>

<style scoped>
.edit-input {
  padding-right: 100px;
}
.cancel-btn {
  position: absolute;
  right: 15px;
  top: 10px;
}
</style>
